import java.util.LinkedList;
import java.util.Stack;

public class ReverseList {
    /**
     * 定义一个函数，输入一个链表的头节点，反转该链表并输出反转后链表的头节点。
     * @param head
     * @return
     */
    public ListNode reverseList(ListNode head) {
        if (head==null||head.next==null)
            return head;
        ListNode prev = null;
        ListNode cur = head;
        while (cur!=null){
            ListNode next =cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }
        return prev;



    }
}
